<?php

class My_View_Helper_IdToUrl extends Zend_View_Helper_Abstract
{
    public function idToUrl($id, $content = null, $attribs = null,$onlyText=false)
    {
        
        $found = $this->view->navigation()->findById($id);

      
       // if(!$found)  throw new Zend_Controller_Exception(sprintf('No found url in ID %s in My_View_Helper_IdToUrl',$id));
         
        if(!$found) return  null;
        
        $url = $found->controller . "/" . $found->action;


        foreach ($found->params as $k => $v)
        {
            $url .=  "/"  . $k .  "/"  . $v;
        }

        $content = is_null($content) ? $found->label : $content;
        
        $content=$this->view->translate($content);
        
        if($onlyText){
            $salida['text']=$content;
            $salida['url']=$url;
            $salida['attribs']=$attribs;
            return $salida;
        }
 
       
        
        return $this->view->anchor($url, $content, $attribs,false);
    }
}
